import path from "node:path";
import { session } from "electron";
import { createRequire } from "node:module";

const require = createRequire(import.meta.url);

const VUE_DEVTOOLS_ID = "nhdogjmejiglipccpnnnanhbledajbpd";
const VUE_DEVTOOLS_BETA_ID = "ljjemllljcmogpfapbkkighbhhppjdbg";

const useExtId = VUE_DEVTOOLS_ID;

export function getVueDevToolsPath(): string | null {
  return path.join(process.cwd(), "dev/vue-devtools/6.6.3_0");
  // return path.join(app.getPath("userData"), "extensions/nhdogjmejiglipccpnnnanhbledajbpd");
}

export async function installVueDevTools() {
  const vueDevToolsPath = getVueDevToolsPath();
  if (vueDevToolsPath) {
    try {
      console.log("detected vue-devtools: ", vueDevToolsPath);
      const ext = await session.defaultSession.loadExtension(vueDevToolsPath, { allowFileAccess: true });
      console.log(`vue-devtools installed: ${ext.name}(${ext.version})`);
    } catch (e: any) {
      console.error("vue-devtools install error, ", e.message);
    }
  }
}
